package com.ruoyi.media.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.media.mapper.DailyReportsMapper;
import com.ruoyi.media.domain.Dailyreports;
import com.ruoyi.media.service.IDailyreportsService;

/**
 * 工作报告Service业务层处理
 * 
 * @author crocodilePole
 * @date 2025-02-18
 */
@Slf4j
@Service
public class DailyreportsServiceImpl implements IDailyreportsService 
{
    @Autowired
    private DailyReportsMapper dailyreportsMapper;

    private static final Integer PROGRESS_NOT_STARTED = 0;

    /**
     * 查询工作报告
     * 
     * @param id 工作报告主键
     * @return 工作报告
     */
    @Override
    public Dailyreports selectDailyreportsById(Long id)
    {
        return dailyreportsMapper.selectDailyreportsById(id);
    }

    /**
     * 查询工作报告列表
     * 
     * @param dailyreports 工作报告
     * @return 工作报告
     */
    @Override
    public List<Dailyreports> selectDailyreportsList(Dailyreports dailyreports)
    {

        return dailyreportsMapper.selectDailyreportsList(dailyreports);
    }

    /**
     * 新增工作报告
     * 
     * @param dailyreports 工作报告
     * @return 结果
     */
    @Override
    public int insertDailyreports(Dailyreports dailyreports)
    {

        //获取用户id
        LoginUser loginUser = SecurityUtils.getLoginUser();
        SysUser user = loginUser.getUser();
        Long userId = user.getUserId();
        dailyreports.setUserId(userId);
        log.info("新增工作记录人:{}", userId);

        //获取系统当前时间
        dailyreports.setCreateTime(DateUtils.getNowDate());
        dailyreports.setUpdateTime(DateUtils.getNowDate());
        return dailyreportsMapper.insertDailyreports(dailyreports);
    }

    /**
     * 修改工作报告
     * 
     * @param dailyreports 工作报告
     * @return 结果
     */
    @Override
    public int updateDailyreports(Dailyreports dailyreports)
    {
        log.info("查询工作记录列表{}", dailyreports);
        dailyreports.setUpdateTime(DateUtils.getNowDate());
        return dailyreportsMapper.updateDailyreports(dailyreports);
    }

    /**
     * 批量删除工作报告
     * 
     * @param ids 需要删除的工作报告主键
     * @return 结果
     */
    @Override
    public int deleteDailyreportsByIds(Long[] ids)
    {
        return dailyreportsMapper.deleteDailyreportsByIds(ids);
    }

    /**
     * 删除工作报告信息
     * 
     * @param id 工作报告主键
     * @return 结果
     */
    @Override
    public int deleteDailyreportsById(Long id)
    {
        return dailyreportsMapper.deleteDailyreportsById(id);
    }
}
